<?php

namespace App\Http\Controllers\Api\V1;


use App\Enums\ResponseCode;
use App\Helpers\FunTool;
use App\Http\Controllers\Api\AbstractApiController;
use App\Http\Resources\JobpositionResource;
use App\Services\Jobposition\JobpositionService;
use App\Services\Page\PageService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

class PageController extends AbstractApiController
{

    private PageService $login;

    public function __construct(PageService $login)
    {
        $this->login = $login;
    }

    /**
     * 系统首页数据
     */
    public function index(Request $request, JobpositionService $service): JsonResponse
    {
        $result = $this->login->index();
        $user = auth('api')->user();
        $region_city = $request->input('region_city', '');
        $result['job_position'] = new JobpositionResource($service->list(
            user: $user,
            categoryId: $result['category'][0]['id'] ?? 0,
            region_city: $region_city,
        ));
        return $this->success(trans("success"), ResponseCode::OK, $result);
    }

    /**
     * 删除指定缓存
     * @param $key
     * @return JsonResponse
     */
    public function deleteCache(Request $request): JsonResponse
    {
        $key = $request->get('key', '');
        return $this->success(trans("success"), ResponseCode::OK, $this->login->deleteCache($key));
    }

    /**
     * 客服
     * @return JsonResponse
     */
    public function customerService(): JsonResponse
    {
        $result['customer_service'] = config('system.customer_service');
        return $this->success(trans("success"), ResponseCode::OK, $result);
    }

    /**
     * 招人信息
     */
    public function recruit(): JsonResponse
    {
        $result = [
            'recruit_url' => config("base.recruit_url"),
            'official_accounts' => FunTool::imageUrl(config("base.official_accounts")),
        ];
        return $this->success(trans("success"), ResponseCode::OK, $result);
    }

    /**
     * 联系我们
     * @return JsonResponse
     */
    public function contact(): JsonResponse
    {

        $result = [
            'email' => config("contact.contact_us_email"),
            'me_or_code' => FunTool::imageUrl(config("contact.me_or_code")),
        ];
        return $this->success(trans("success"), ResponseCode::OK, $result);
    }
    
   
}
